function loadFriends() {
  var req = opensocial.newDataRequest();
  req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
  req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS'), 'viewer_friends');
  req.send(onLoadFriends);
}

function onLoadFriends(data) {
  var viewer = data.get('viewer').getData();
  var viewer_friends = data.get('viewer_friends').getData();
  
  html = new Array();
  html.push('<ul>');
  viewer_friends.each(function(person) {
    html.push('<li>'+person.getDisplayName()+'</li>');
  });
  html.push('</ul>');
  document.getElementById('friends').innerHTML = html.join('');
  alert(html.join(''));
}

function init() {
  loadFriends();
}